import { resetRouter, routes } from "@/router";
import { defineStore } from "pinia";
import { ref } from "vue";
import type { RouteRecordRaw } from "vue-router";

// 定义Store返回类型接口
interface MenuStore {
  menuList: RouteRecordRaw[];
  setMenuList: (filterRoutes: RouteRecordRaw[]) => void;
  clearMenuList: () => void;
}

export const useMenuStore = defineStore('hm-menu', (): MenuStore => {
  const menuList = ref<RouteRecordRaw[]>([...routes]);

  const setMenuList = (filterRoutes: RouteRecordRaw[]) => {
    menuList.value = [...menuList.value, ...filterRoutes];
  };

  const clearMenuList = () => {
    // 重置左侧菜单
    menuList.value = [...routes];
    // 重置路由系统
    resetRouter();
  };

  return {
    // 显式返回数组值以匹配接口类型
    get menuList(): RouteRecordRaw[] {
      return menuList.value;
    },
    setMenuList,
    clearMenuList
  };
});